from typing import Optional

from pydantic import BaseModel, Field


class UserInfo(BaseModel):  # 定制请求体body的模型类，期待的json对象的属性
    nick_name: Optional[str] = Field(None, max_length=20,
                                     regex=r'[\u4e00-\u9fa5]+', title='中文的昵称')
    phone: Optional[str] = Field(None, regex=r'^1[3-9]\d{9}$', title='手机号')
    email: Optional[str] = Field(None, regex=r'^\w+?@.+\.(com|cn|net|org|edu)$', title='邮箱')

class RegistUser(UserInfo):
    # 请求体的模型类是可以继承的
    username: Optional[str] = Field(..., regex=r'^[a-zA-Z]\w{5,}$')
    password: Optional[str] = Field(..., min_length=8, title='口令')
    password2: Optional[str] = Field(..., min_length=8, title='确认口令')

class PwdSecure(BaseModel):
    title: Optional[str] = Field(..., max_length=20, title='问题描述')
    result: Optional[str] = Field(..., max_length=20, title='问题答案')